﻿using ControlHelper.Attributes;
using Creator.Access.Core;
using Newtonsoft.Json;
using System;


namespace Creator.Access
{
    /// <summary>
    /// 设备需要读取的信息所需要的配置 
    /// </summary>   
    public class DeviceInfo
    {  
    
        /// <summary>
        /// 对应的设备编号
        /// </summary> 
        [Hide]
        public int DeviceID { get; set; }
        /// <summary>
        /// 设备信息编号
        /// </summary>
        [Hide]
        public int DeviceInfoID { get; set; }
        /// <summary>
        /// 设备信息名称
        /// </summary>
        [NickName("设备信息名称")] 
        public string DeviceInfoName { get; set; }
      
        /// <summary>
        /// 对设备的操作类型
        /// </summary>
        [JsonConverter(typeof(PolyConverter))] 
        [NickName("读取类型")]
        public OperationBase  Operation { get; set; }
         
        /// <summary>
        /// 刷新数据间隔  单位:毫秒 
        /// </summary> 
        [NickName("数据刷新间隔(毫秒)")]
        public int RefreshInterval { get; set; } = 2000;
    

        #region 操作的创建(弃用 20220830)

        /// <summary>
        /// 获取所有操作类型
        /// <para></para>
        /// <see cref=" Utility.Reflection.GetInheritors"/>
        /// </summary>
        /// <returns></returns>
        //public ClassData GetOperations() => Utility.Reflection.GetClassData<OperationBase>();

        /// <summary>
        /// 创建一个操作类型
        /// </summary>
        /// <param name="name"></param>
        /// <exception cref="Exception"></exception>
        //public void CreateOpertaion(string name)
        //{ 
        //    Operation = Utility.Reflection.CreateObjectShortName<OperationBase>(name);
        //    if (Operation == null)
        //    {
        //        throw new Exception($"{info} 创建失败！");
        //    } 
        //}

        #endregion
         
        [JsonIgnore]
        private  string info => $"设备编号'{DeviceID}' 设备信息编号'{DeviceInfoID}' 设备信息名称'{DeviceInfoName}';";


    } 
}
